﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Najak;

namespace Falon.Animations
{
	class Shake : EntityAnimation
	{
		public double Time;
		public double FFactor = 720;
		public double Amplitude = 10;
		public double DFactor = 1.5f;
		public Vector2 Direction = new Vector2(1, 0);

		public Shake(Entity entity) : base(entity)
		{
		}

		public override void Update(GameTime gameTime)
		{
			Time += gameTime.ElapsedGameTime.TotalSeconds;
			double dfactor = DFactor * gameTime.ElapsedGameTime.TotalSeconds;
			double ar = Amplitude * dfactor;
			Amplitude -= ar;
			if (Amplitude < 3)
			{
				Remove();
				return;
			}
			double angle = Time * FFactor;
			double offset = Amplitude * Math.Cos(angle);
			Entity.LocationOffset = Direction * (float)offset;
		}

		protected override void OnRemoved()
		{
			base.OnRemoved();

			Entity.LocationOffset = Vector2.Zero;

			// Make Barrel Explode.
		}

	}
}
